export const loadMore = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    let selectDropdown;
    if (el.classList.contains('mytabelbox')) {
      selectDropdown = document.querySelector('.mytabelbox .el-scrollbar__wrap') as HTMLElement;
    } else {
      selectDropdown = document.querySelector('.single-select-loadmore .el-select-dropdown__wrap') as HTMLElement;
    }
    if (selectDropdown) {
      selectDropdown.addEventListener('scroll', () => {
        const scrollDistance = selectDropdown.scrollHeight - selectDropdown.scrollTop - selectDropdown.clientHeight;
        if (scrollDistance <= 1) {
          binding.value(); // 触发加载更多的逻辑
        }
      });
    }
  },
  unmounted(el: HTMLElement) {
    let selectDropdown;
    if (el.classList.contains('mytabelbox')) {
      selectDropdown = document.querySelector('.mytabelbox .el-scrollbar__wrap') as HTMLElement;
    } else {
      selectDropdown = document.querySelector('.single-select-loadmore .el-select-dropdown__wrap') as HTMLElement;
    }

    if (selectDropdown) {
      selectDropdown.removeEventListener('scroll', () => {});
    }
  }
};
